<template>
  <div class="tips_recommend">

    <div class="tips">
      <div class="title">推荐文章</div>
      <div class="item" >
        <span></span>
        <p v-for="item in articleList"> <a
            :href="'/health/tips/details/' + item.username + '/' + item.title"
            @click="addReadNumber(item)"
        >{{item.title}}</a></p>
      </div>
    </div>

  </div>
</template>
<script>
export default {
  data() {
    return {
      healthTips: {},
      articleList: []
    };
  },
  created() {
    this.getAllHealthTips();
  },
  methods: {
    /* 根据管理员用户名和文章确定唯一文章获取文章详情 */
    /* 获取全部的文章 */
    getAllHealthTips() {
      this.$axios.get("/all/health/tips/" + 1).then((res) => {
        console.log("全部文章--->", res);
        this.healthTips = res.data.data.data.records;
        this.healthTips.forEach(item=>{
          this.articleList.push({id: item.id, title: item.title, username: item.username})
        })
        console.log(this.articleList)
        this.total = res.data.data.data.total;
      });
    },
    /* 阅览次数加1 */
    addReadNumber(item) {
      let formData = new FormData();
      formData.append("id", item.id);
      this.$axios.post("/health/tips/readNumber/add", formData);
    },
  },
};
</script>
<style lang="less" scoped>
@import "../style/tips_recommend.less";
</style>
